package com.sinoglobal.ningxia.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sinoglobal.ningxia.R;

/**
 * @author sbk
 * @createdate 2013-12-15 下午2:08:22
 * @Description: 答题适配器
 */
public class InteractionAnswerErrorGdAdapter extends BaseAdapter {
	private Context con;
	private List<String> aListItem=new ArrayList<String>();;
	private LinearLayout.LayoutParams lp;
	private int select, right;

	public InteractionAnswerErrorGdAdapter(Context con) {
		super();
		this.con = con;
		lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		// 此处相当于布局文件中的Android:layout_gravity属性
		lp.gravity = Gravity.RIGHT;
	}

	public void setaListItem(List<String> aListItem, int select, int right) {
		this.aListItem = aListItem;
		this.select = select;
		this.right = right;
		notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		//Auto-generated method stub
		return aListItem.size();
	}

	@Override
	public Object getItem(int position) {
		//Auto-generated method stub
		return aListItem.get(position);
	}

	@Override
	public long getItemId(int position) {
		//Auto-generated method stub
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		LinearLayout layout = (LinearLayout) LayoutInflater.from(con).inflate(R.layout.interaction_answer_layout_gd_item, null);
		LinearLayout l1 = (LinearLayout) layout.findViewById(R.id.l1);
		RelativeLayout r1 = (RelativeLayout) layout.findViewById(R.id.rely);
		TextView tv = (TextView) layout.findViewById(R.id.text1);
		TextView btn = (TextView) layout.findViewById(R.id.bt_id);

		l1.setOrientation(LinearLayout.HORIZONTAL);
		r1.setVisibility(View.GONE);
		tv.setText(aListItem.get(position));
		tv.setVisibility(View.VISIBLE);
		btn.setLayoutParams(lp);
		btn.setEnabled(false);
		if (position == select) {
			btn.setBackgroundResource(R.drawable.answer_radio_btn_select);
			tv.setTextColor(con.getResources().getColor(R.color.red));
		}
		if (position == right) {
			tv.setTextColor(con.getResources().getColor(R.color.green));
		}
		return layout;
	}

}
